package com.example.controller;

import com.example.common.Result;
import com.example.entity.OrganizationActivity;
import com.example.service.OrganizationActivityService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 组织活动前端操作接口
 **/
@RestController
@RequestMapping("/organizationActivity")
public class OrganizationActivityController {

    @Resource
    private OrganizationActivityService organizationActivityService;

    /**
     * 新增活动
     */
    @PostMapping("/add")
    public Result add(@RequestBody OrganizationActivity activity, @RequestParam Long leaderId) {
        return organizationActivityService.add(activity, leaderId);
    }

    @PutMapping("/update")
    public Result updateById(@RequestBody OrganizationActivity activity, @RequestParam Long leaderId) {
        return organizationActivityService.updateById(activity, leaderId);
    }

    /**
     * 删除活动
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Long id) {
        organizationActivityService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        organizationActivityService.deleteBatch(ids);
        return Result.success();
    }



    /**
     * 根据ID查询活动
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Long id) {
        OrganizationActivity activity = organizationActivityService.selectById(id);
        return Result.success(activity);
    }

    /**
     * 查询所有活动
     */
    @GetMapping("/selectAll")
    public Result selectAll(OrganizationActivity activity) {
        List<OrganizationActivity> list = organizationActivityService.selectAll(activity);
        return Result.success(list);
    }

    /**
     * 分页查询活动
     */
    @GetMapping("/selectPage")
    public Result selectPage(OrganizationActivity activity,
                           @RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<OrganizationActivity> page = organizationActivityService.selectPage(activity, pageNum, pageSize);
        return Result.success(page);
    }
}
